import type { RouteRecordRaw } from 'vue-router'
import { basicRouteList } from './basic'

declare type Recordable<T = any> = Record<string, T>

// import.meta.glob() 直接引入所有的模块 Vite 独有的功能
const modules = import.meta.glob('./modules/**/*.ts', { eager: true })
const basicRouteModuleList: RouteRecordRaw[] = []

// 加入到路由集合中
Object.keys(modules).forEach((key) => {
  // 获取模块中的 default export
  const mod = (modules as Recordable)[key].default || null

  if (mod != null) {
    const modList = Array.isArray(mod) ? [...mod] : [mod]
    // 将模块中的 AppRouteModule 添加到基础路由
    basicRouteModuleList.push(...modList)
  }
})

export const basicRoutes = [...basicRouteModuleList, ...basicRouteList]
